/*******************************************************************
 *   > File Name: sd_relocate.c
 *   > Author: fly
 *   > Mail: XXXXXXXX@icode.com
 *   > Create Time: Thu 19 Mar 2020 09:34:56 AM CST
 ******************************************************************/
#define SD_START_BLOCK      45
#define SD_BLOCK_CNT        32
#define DDR_START_ADDR      0x23E00000

typedef unsigned int bool;

//通道号：0，或者2；
//开始扇区：45
//读取扇区个数：32
//读取后放入内存地址:0x23E00000
//with_init:0

typedef bool(*pCopySDMMC2Mem)(int, unsigned int, unsigned short, unsigned int*, bool);
typedef void(*pBL2Type)(void);

//从SD卡第45扇区开始，复制32个扇区内容到DDR的0x23E00000,
//然后跳转到23E00000去执行
void copy_bl2_2_ddr(void)
{
    //读取SD卡扇区到DDR中去
    pCopySDMMC2Mem p1 = (pCopySDMMC2Mem)(*(unsigned int*)0xD0037F98);

    p1(2, SD_START_BLOCK, SD_BLOCK_CNT, (unsigned int *)DDR_START_ADDR, 0);//读取SD卡到DDR中
    
    //跳转到DDR中的BL2去执行
    pBL2Type p2 = (pBL2Type)DDR_START_ADDR;
    p2();
}
